home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / VideoToolboxSources / ReadLuminanceRecord.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-21  |  4.6 KB  |  123 lines  |  [TEXT/KAHL]

  1. /*
  2. ReadLuminanceRecord.c
  3. 7/29/91 dgp
  4. Reads a LuminanceRecord?.h file at runtime. In the past these calibration-data files
  5. could only be used by #including them at compile time.
  6.  
  7. All heap allocations in ReadLuminanceRecord are temporary, recovered before returning.
  8. However, it calls ReadAssignmentFile(), which allocates space for each string. This space
  9. may be recovered by calling free() for each string.
  10.  
  11. HISTORY:
  12. 8/24/91    dgp    Made compatible with THINK C 5.0.
  13.             Preserve default values of LP->VMin and LP->VMax if no new values are read.
  14. 8/26/91    dgp    Rewrote using new SetVariable() routine, which makes the code easier to
  15.             read. 
  16. 12/17/92 dgp Added dacSize.
  17. 12/21/92 dgp Changed type of dacSize from long to short.
  18. */
  19.  
  20. #include "VideoToolbox.h"
  21. #include "Luminance.h"
  22. #define VARIABLES 51L    /* only 47 are used at present */
  23.  
  24. #if 0
  25.     void main()
  26.     {
  27.         static luminanceRecord LR,LR2;
  28.         
  29.         #include "LuminanceRecord1.h"
  30.         ReadLuminanceRecord("LuminanceRecord1.h",&LR2,echoAssignments+echoComments+echoFile);
  31.         /* You can use the THINK C debugger to compare LR and LR2, which should be
  32.         identical in content. */
  33.     }
  34. #endif
  35.  
  36. int ReadLuminanceRecord(char *filename,luminanceRecord *LP,int echo)
  37. {
  38.     Variable *p,*p0;
  39.     int i,j,k=0,n;
  40.     double VMin,VMax;
  41.     void **allocation;
  42.     
  43.     /* get default values */
  44.     VMin=LP->VMin;
  45.     VMax=LP->VMax;
  46.     
  47.     p0=p=(Variable *)malloc(VARIABLES*sizeof(Variable));
  48.     allocation=(void **)malloc(VARIABLES*sizeof(void *));
  49.     if(p==NULL || allocation==NULL){
  50.     noRoom:
  51.         PrintfExit("\nReadLuminanceRecord: no room for temporary storage\n\007");
  52.     }
  53.  
  54.     /* Create a structure describing the variables. */
  55.     j=0;
  56.     p[j++]=SetVariable(shortType,&LP->dacSize,"LR.dacSize");
  57.     p[j++]=SetVariable(doubleType,&LP->LMin,"LR.LMin");
  58.     p[j++]=SetVariable(doubleType,&LP->LMax,"LR.LMax");
  59.     p[j++]=SetVariable(doubleType,&LP->LBackground,"LR.LBackground");
  60.     p[j++]=SetVariable(shortType,&LP->VBackground,"LR.VBackground");
  61.     p[j++]=SetVariable(shortType,&LP->screen,"LR.screen");
  62.     p[j++]=SetVariable(stringType,&LP->id,"LR.id");
  63.     p[j++]=SetVariable(stringType,&LP->name,"LR.name");
  64.     p[j++]=SetVariable(stringType,&LP->date,"LR.date");
  65.     p[j++]=SetVariable(stringType,&LP->notes,"LR.notes");
  66.     p[j++]=SetVariable(doubleType,&LP->dpi,"LR.dpi");
  67.     p[j++]=SetVariable(doubleType,&LP->Hz,"LR.Hz");
  68.     p[j++]=SetVariable(stringType,&LP->units,"LR.units");
  69.     p[j++]=SetVariable(longType,&LP->coefficients,"LR.coefficients");
  70.     for(i=0;i<sizeof(LP->p)/sizeof(LP->p[0]);i++){
  71.         p[j]=SetVariable(doubleType,&LP->p[i],allocation[k++]=malloc(16));
  72.         if(p[j].name==NULL)goto noRoom;
  73.         sprintf(p[j++].name,"LR.p[%d]",i);
  74.     }
  75.     p[j++]=SetVariable(doubleType,&LP->polynomialError,"LR.polynomialError");
  76.     for(i=0;i<sizeof(LP->q)/sizeof(LP->q[0]);i++){
  77.         p[j]=SetVariable(doubleType,&LP->q[i],allocation[k++]=malloc(16));
  78.         if(p[j].name==NULL)goto noRoom;
  79.         sprintf(p[j++].name,"LR.q[%d]",i);
  80.     }
  81.     p[j++]=SetVariable(doubleType,&LP->quadraticError,"LR.quadraticError");
  82.     for(i=0;i<sizeof(LP->power)/sizeof(LP->power[0]);i++){
  83.         p[j]=SetVariable(doubleType,&LP->power[i],allocation[k++]=malloc(16));
  84.         if(p[j].name==NULL)goto noRoom;
  85.         sprintf(p[j++].name,"LR.power[%d]",i);
  86.     }
  87.     p[j++]=SetVariable(doubleType,&LP->powerError,"LR.powerError");
  88.     for(i=0;i<sizeof(LP->fixedPower)/sizeof(LP->fixedPower[0]);i++){
  89.         p[j]=SetVariable(doubleType,&LP->fixedPower[i],allocation[k++]=malloc(32));
  90.         if(p[j].name==NULL)goto noRoom;
  91.         sprintf(p[j++].name,"LR.fixedPower[%d]",i);
  92.     }
  93.     p[j++]=SetVariable(doubleType,&LP->fixedPowerError,"LR.fixedPowerError");
  94.     p[j++]=SetVariable(doubleType,&LP->r,"LR.r");
  95.     p[j++]=SetVariable(doubleType,&LP->g,"LR.g");
  96.     p[j++]=SetVariable(doubleType,&LP->b,"LR.b");
  97.     p[j++]=SetVariable(doubleType,&LP->gainAccuracy,"LR.gainAccuracy");
  98.     p[j++]=SetVariable(doubleType,&LP->gm,"LR.gm");
  99.     p[j++]=SetVariable(shortType,&LP->rangeSet,"LR.rangeSet");
  100.     p[j++]=SetVariable(shortType,&LP->L.exists,"LR.L.exists");
  101.     /*
  102.     Special handling is required for LR.VMin and LR.VMax, which used to be doubles but
  103.     are now shorts. They are assigned floating point values 0.0 and 255.0 in
  104.     old LuminanceRecord files, and are assigned short values 0 and 255 in
  105.     newer LuminanceRecord files. ReadAssignmentFile() won't do type conversion.
  106.     To handle both flavors we read LR.VMin and LR.VMax into
  107.     temporary double variables before converting them to shorts.
  108.     */
  109.     p[j++]=SetVariable(doubleType,&VMin,"LR.VMin");
  110.     p[j++]=SetVariable(doubleType,&VMax,"LR.VMax");
  111.     p[j++]=SetVariable(0,NULL,NULL);                /* Mark end of list */
  112.     if(j>VARIABLES){
  113.         PrintfExit("ReadLuminanceRecord: Oops. I used more variables than I allocated."
  114.             " %ld>%ld\n\007",(long)j,VARIABLES);
  115.     }
  116.     n=ReadAssignmentFile(filename,p0,echo);
  117.     LP->VMin=VMin;
  118.     LP->VMax=VMax;
  119.     free(p);
  120.     for(i=0;i<k;i++)free(allocation[i]);
  121.     return n;
  122. }
  123.